$(function() {});

// 充值按钮
$(document).on('click', '.recharge-btn', function() {
	// 格式化输入
	// 判断输入值是否合法
	var regu = '^[0-9]+[.][0-9]{0,3}$',
		re = new RegExp(regu),
		s = $.trim($('.recharge-input').val());
	if (s.indexOf('.') < 0) {
		s += '.00';
    }
    if(s != Math.floor(s)) {
        weui.alert('请输入整数');
        return false;
    }
	if (re.test(s)) {
		// 输入合法
		var loading = weui.loading('loading', {
			className: 'custom-classname',
		});
		var result = Model.user.rechargeRedRice({ price: parseInt(s) });
		if (result.code) {
			Common.fn.formatOutput(result);
			loading.hide();
			return false;
		}
		console.log(JSON.stringify(result));
		loading.hide();
		
		weui.alert('充值成功！', function() {
			location.href = 'balance.html';
		});
	} else {
		// 输入不合法
		weui.alert('输入金额不符合规范');
		return false;
	}
});
